package com.msmall.community.admin.action;

import java.io.File;

import com.msmall.base.action.HTMLBaseAction;
import com.msmall.base.util.ConstantDB;
import com.msmall.base.util.ConstantUrl;
import com.msmall.community.common.model.Link;
import com.msmall.community.common.service.LinkManager;

public class LinkAction extends HTMLBaseAction{
	  
	private static final long serialVersionUID = 8929866946479405130L;
	private Long linkid;
	private File image;
	private String imageContentType; // 文件的内容类型
	private String imageFileName; // 上传文件名
	private Link link;
	private LinkManager linkManager;

	public String execute(){
		page.setClazz(Link.class);
		page.setOrderBy("orders");
		page.setOrder("asc");
		linkManager.getPagination(page);
		page.setUrl(ConstantUrl.ADMIN_LINK_INDEX);
		return SUCCESS;
	}
	
	public String create(){
		linkid = null;
		link = null;
		return SUCCESS;
	}
	
	public String update(){
		link = (Link) linkManager.get(Link.class, linkid);
		return SUCCESS;
	}
	
	public String save(){
		if(link.getEnabled() == null){
			link.setEnabled(ConstantDB.UNAVALIABLE);
		}
		linkManager.saveLink(image, imageFileName, link, getUserAgentType(), getUserid());
		return SUCCESS;
	}

	public Long getLinkid() {
		return linkid;
	}

	public void setLinkid(Long linkid) {
		this.linkid = linkid;
	}

	public File getImage() {
		return image;
	}

	public void setImage(File image) {
		this.image = image;
	}

	public String getImageContentType() {
		return imageContentType;
	}

	public void setImageContentType(String imageContentType) {
		this.imageContentType = imageContentType;
	}

	public String getImageFileName() {
		return imageFileName;
	}

	public void setImageFileName(String imageFileName) {
		this.imageFileName = imageFileName;
	}

	public Link getLink() {
		return link;
	}

	public void setLink(Link link) {
		this.link = link;
	}

	public void setLinkManager(LinkManager linkManager) {
		this.linkManager = linkManager;
	}
}